package exception;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import java.sql.SQLException;
//@Component
public class MyExceptionHandler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request,
                                         HttpServletResponse response,
                                         Object handler,
                                         Exception ex) {
        if(ex instanceof SQLException){
            return new ModelAndView("sql-error");
        }else if(ex instanceof MyException){
            return new ModelAndView("my-error");
        }else{
            return new ModelAndView("error");
        }

    }
}
